<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/mobile/include/taglib.jsp"%>
<html>
<head>
	<title>商品搜索</title>
	<%@include file="/WEB-INF/views/mobile/include/head.jsp" %>
	<script type="application/javascript" src="${ctxFront}/js/cookie.js"></script>
	<style type="text/css">

	</style>
	<script type="text/javascript">
		var appId = '${appId}';
		var sid="${merchant.id}";
		var mobile="${mobile}";
		var classifyId = "${classifyId}";
		var shopModel = "${shopModel}";
		var products = new Array();
		var totalNumber = ${totalNumber};
		var totalAmount = ${totalAmount};
		var ctxFront = "${ctxFront}";
		var ctxShop = "${ctxShop}";
		$(document).ready(function() {
			//$(".ui-input-search").removeClass("ui-corner-all").css("position", "fixed").css("position", "_absolute").css("top", "0px").css("width", $(window).width()-40).css("margin","0px").css("box-shadow", "none").css("z-index", "1001");
			//$("#search").focus();
			$("#searchForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			
			if(${fn:length(list)}>0){  //加载进来时封装商品信息
				products = new Array();
				<c:forEach items="${list}" var="product" varStatus="ps">
					var item = new Object();
					item.id="${product.id}";
					item.price=${product.price};
					item.startSaleNum=${product.startSaleNum}; //起购量
					item.purchaseNum=${product.purchaseNum};   //限购量
					item.cartId="${product.cartId}";	 //购物车里对应该商品编号
					item.number=${product.number};   //购物车里对应该商品购买数量
					item.amount=${product.amount};   //购物车里对应该商品购买金额
					products.push(item);
					//调用判断商品是否可以操作
					checkAddOrDiffIcon(item);
				</c:forEach>
			}
			$(".totalAmount strong").text("￥"+changeTwoDecimal_f(totalAmount));
			//缓存搜索key
			$.cookie("searchParam", '${searchParam}');
		});
		function toSettlement(){
			//验证是否登录
			if(!checkLogin()) return;
			
			loading('正在提交，请稍等...');
			setTimeout(function(){
				hideLoader();
				document.location="${ctxShop}/order/toSettlement?sid="+sid+"&mobile="+mobile+"&classifyId="+classifyId+"&shopModel="+shopModel+"&appId="+appId;				
			},1000);
		}
		function showProductDetail(url){
			loading('正在跳转，请稍等...');
			setTimeout(function(){
				hideLoader();
				document.location=url+"&sid="+sid+"&mobile="+mobile+"&classifyId="+classifyId+"&shopModel="+shopModel+"&appId="+appId;				
			},1000);
		}
		function showShoppingCart(){
			//验证是否登录
			if(!checkLogin()) return;
			
			loading('正在跳转，请稍等...');
			setTimeout(function(){
				hideLoader();
				document.location="${ctxShop}/shoppingcart?sid="+sid+"&mobile="+mobile+"&classifyId="+classifyId+"&shopModel="+shopModel+"&appId="+appId;				
			},1000);
		}
	</script>
	<script type="text/javascript"> 
		$(document).ready(function() {
			//预加载图片
			startLoadImage();
		});
		function startLoadImage(){
			$(".displayImages").each(function(index){
				loadImage($(this).attr("id"),$(this).attr("path"),loadResult);
			});
		}
	</script>
	<script type="text/javascript"> 
		function iEventGetNavgitionInfo(){
			var result = {
				titleView:1,
			    leftBtn:{ 
			    	type:0,	//0只显示返回,1只显示关闭，2显示返回，关闭
					backFun:""   //返回执行的事件，不带的话由iOS控制。
				}
			};
			if($global_isAndroid){
				window.control.onJsComplete(JSON.stringify(result));
				return;
			}
			return JSON.stringify(result);
		}
		function iEventSearch(key){
			$("#searchParam").val(key);
			$("#searchForm").submit();
		}
		function iEventShowMore(){
			showMoreMenu();
		}
	</script>
</head>
<body data-role="page">
	<div role="main" class="ui-content" style="padding:0em 0em 3.25em 0em;">
		<div id="popup" data-role="popup" data-position-to="window" data-overlay-theme="a" data-theme="b" class="ui-content">
		  <p></p>
		</div>
		<%@include file="/WEB-INF/views/mobile/layouts/checkLoginPopup.jsp" %>
		<form id="searchForm" action="${ctxShop }/search/list?sid=${merchant.id}&mobile=${mobile}&classifyId=${classifyId}&shopModel=${shopModel}&appId=${appId}" method="post" style="margin-bottom: 0em;">
		<input id="totalAmount" name="totalAmount" type="hidden" value="${totalAmount }" />
		<input id="searchParam" name="searchParam" value="${searchParam }" type="hidden"/>
		<c:if test="${fn:length(list) != 0}">
		<div class="custom-module">
		<ul data-role="listview" class="custom-list">
		<c:forEach items="${list}" var="product" varStatus="vs">
			<li id="${product.cartId }" data-icon="false">
				<a id="${product.id }" data-transition="slide" href="#" style="background-color: #fff;">
					<div class="product-img" onclick="showProductDetail('${ctxShop}/product/detail?id=${product.id }');">
				    	<img id="photo${vs.index }" class="displayImages" src="${ctxFront }/images/loading.png" path="${ctxShop}/download?filePath=${product.logoUrl }"/>
				    </div>
				    <h2><label class="float-left">${product.name}</label></h2>
					<p><label class="huise-color">${product.assisTitle }</label></p>
				    <p><label class="float-left amount"><strong>￥${product.price }</strong></label><label class="float-left unit-color"> / ${product.productUnit.name }</label></p>
			        <p>
			        	<img class="float-left diff" status="0" onclick="diffProductCart('${product.id}', 0)" alt="" src="${ctxFront }/images/shop/diff-1.png"/>
			        	<label class="float-left choice-num"><strong>${product.number }</strong></label>
			        	<img class="float-left add" status="1" onclick="addProductCart('${product.id}')" alt="" src="${ctxFront }/images/shop/add-2.png"/>
			        </p>
			    </a>
		    </li>
		</c:forEach>
		</ul>
		</div>
		</c:if>
		<div class="cart-empty" style="${fn:length(list) > 0?'display:none;':(init?'display:none;':'')}">
			<img alt="" src="${ctxFront }/images/shop/gwc_0.png" width="50" height="50" style="vertical-align: middle;">&nbsp;没有您搜索的商品！
		</div>
		</form>
	</div>
	<div data-role="footer" class="ui-footer" data-position="fixed" data-tap-toggle="false">
		<div class="float-left footer-left">
			<div class="a"><label class="float-left">总金额：</label><label class="float-left amount totalAmount"><strong>￥${totalAmount }</strong></label></div>
	    </div>
		<div class="float-right footer-right">
			<div class="b"><img alt="" src="${ctxFront }/images/shop/gwc_0.png" onclick="showShoppingCart()"></div>
			<div class="badger-css totalNumber-badger" style="${totalNumber==0?'display:none;':'' }" onclick="showShoppingCart()"><div class="badger-badge totalNumber" style="border-radius:50%">${totalNumber }</div></div>
	    </div>
	</div><!-- /footer -->
</body>
</html>
